﻿// <copyright file="ColorChooserViewModel.cs" company="Oleg V. Polikarpotchkin">
// Copyright © 2009 Oleg V. Polikarpotchkin. All Right Reserved
// </copyright>
// <author>Oleg V. Polikarpotchkin</author>
// <email>ov-p@yandex.ru</email>
// <date>2009-06-12</date>
// <summary>OpenWPFChart library.
// ColorChooser User Control ViewModel.
// </summary>
// <revision>$Id$</revision>

using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Windows.Media;

namespace OpenWPFChart.Helpers.ChooseColorDialog
{
	/// <summary>
	/// ColorChooser control ViewModel.
	/// </summary>
	class ColorChooserViewModel : INotifyPropertyChanged
	{
		Color selectedColor = Colors.Transparent;
		/// <summary>
		/// Gets or sets the color selected.
		/// </summary>
		/// <value>Color value.</value>
		public Color SelectedColor
		{
			get { return selectedColor; }
			set
			{
				if (selectedColor != value)
				{
					selectedColor = value;
					NotifyPropertyChanged("SelectedColor");
				}
			}
		}

		Color opaqueColor = Colors.Black;
		/// <summary>
		/// Gets or sets the opaque color part from the color selected.
		/// </summary>
		/// <value>Color value.</value>
		public Color OpaqueColor
		{
			get { return opaqueColor; }
			set
			{
				value.A = 255;
				if (opaqueColor != value)
				{
					opaqueColor = value;
					NotifyPropertyChanged("OpaqueColor");

					value.A = (byte)(Opacity * 255);
					SelectedColor = value;
				}
			}
		}

		double opacity = 1.0;
		/// <summary>
		/// Gets or sets the opacity color part.
		/// </summary>
		/// <value>double value in [0, 1] range.</value>
		public double Opacity
		{
			get { return opacity; }
			set
			{
				if (opacity != value)
				{
					opacity = value;
					NotifyPropertyChanged("Opacity");

					Color clr = OpaqueColor;
					clr.A = (byte)(Opacity * 255);
					SelectedColor = clr;
				}
			}
		}

		bool isColorPickerVisible;
		/// <summary>
		/// Gets or sets a value indicating whether the color picker is visible.
		/// </summary>
		/// <value>
		/// 	<c>true</c> if the color picker is visible; otherwise, <c>false</c>.
		/// </value>
		public bool IsColorPickerVisible
		{
			get { return isColorPickerVisible; }
			set 
			{
				if (isColorPickerVisible != value)
				{
					isColorPickerVisible = value;
					NotifyPropertyChanged("IsColorPickerVisible");
				}
			}
		}

		#region INotifyPropertyChanged Members
		public event PropertyChangedEventHandler PropertyChanged;

		void NotifyPropertyChanged(string propertyName)
		{
			if (PropertyChanged != null)
				PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
		}
		#endregion INotifyPropertyChanged Members
	}
}
